package com.tom.architect.party3.day25;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.tom.architect.R;
import com.tom.architect.party3.day25.okhttp.Call;
import com.tom.architect.party3.day25.okhttp.Callback;
import com.tom.architect.party3.day25.okhttp.OkHttpClient;
import com.tom.architect.party3.day25.okhttp.Request;
import com.tom.architect.party3.day25.okhttp.RequestBody;
import com.tom.architect.party3.day25.okhttp.Response;

import java.io.File;
import java.io.IOException;

public class MainActivity25 extends AppCompatActivity {
    private static final String TAG = "TAG";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main25);

        File file = new File("");

        // 自己实现okHttp调用。
        OkHttpClient client = new OkHttpClient();
        RequestBody requestBody = new RequestBody()
                .type(RequestBody.FORM)
                .addParam("file", RequestBody.create(file)) // 传输文件
                .addParam("file2", RequestBody.create(file))
                .addParam("pageNo", 1)
                .addParam("platform", "android")
                .addParam("pageSize", 10);

        Request request = new Request.Builder()
                .url("https://www.baidu.com")
                .post(requestBody)
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e(TAG, "onFailure: " + e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.e(TAG, "onResponse: " + response.string());
            }
        });
    }

}
